///////////////////////////////////////////////////////////////////////////////
// File:        Console.cc
// Author:      671643387@qq.com
// Description:
///////////////////////////////////////////////////////////////////////////////

#include "Console.hpp"

///////////////////////////////////////////////////////////////////////////////
void Console::GetCursorPos(int&x, int &y)
{
#if defined(__WINDOWS__)
    HANDLE hConsole = ::GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordScreen = {0, 0};
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    ::GetConsoleScreenBufferInfo(hConsole, &csbi);
    x = csbi.dwCursorPosition.X;
    y = csbi.dwCursorPosition.Y;
#endif
}

void Console::SetCursorPos(int x, int y)
{
#if defined(__WINDOWS__)
    COORD coord = {x, y};
    ::SetConsoleCursorPosition(::GetStdHandle(STD_OUTPUT_HANDLE),
        coord);
#endif
}

void Console::SetColors(int f, int b)
{
#if defined(__WINDOWS__)
    ::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), 
        (WORD)(f | b));
#endif
}

void Console::SetDefaultColors(void)
{
#if defined(__WINDOWS__)
    ::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), 
        (WORD)(foreground_WHITE | background_BLACK));
#endif
}